from django.db import models
from apps.user.models import User
from apps.order.models import Order

class DeliveryStaff(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name='用户')
    is_active = models.BooleanField(default=True, verbose_name='是否在职')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '配送员'
        verbose_name_plural = verbose_name

class Delivery(models.Model):
    DELIVERY_STATUS = (
        ('assigned', '已分配'),
        ('picked', '已取货'),
        ('delivering', '配送中'),
        ('completed', '已完成'),
    )
    
    order = models.OneToOneField(Order, on_delete=models.CASCADE, verbose_name='订单')
    staff = models.ForeignKey(DeliveryStaff, on_delete=models.CASCADE, verbose_name='配送员')
    status = models.CharField(max_length=20, choices=DELIVERY_STATUS, default='assigned', verbose_name='配送状态')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    completed_at = models.DateTimeField(null=True, blank=True, verbose_name='完成时间')

    class Meta:
        verbose_name = '配送记录'
        verbose_name_plural = verbose_name 